
const process = require('process')
const utils = require('./utils')
execute()
function execute() {
    if (!process.argv.length) {
        throw new TypeError('必须输入工具方法名称')
    }
    const [, , func, params] = process.argv
    if (utils[func]) {
        process.stdout.write(JSON.stringify({ __: utils[func](...JSON.parse(params).__) }))
    } else {
        throw new TypeError(`工具方法[${func}]不存在`)

    }
}
const $utils = new Proxy({}, {
    get(target, p, receiver) {
        return (...rest) => {
            try {
                return JSON.parse(
                    pm.execute(
                        "./apifox-utils/index.js",
                        [p, JSON.stringify({ __: rest })],
                        {
                            windowsEncoding: 'utf8'
                        })).__
            } catch (err) {
                console.error(err)
            }

        }
    },
    set(target, p, newValue, receiver) { }
})